package finance;

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import org.junit.Test;

public class PageDistributionTest {
    public double f(double x) {
        return 7 + Math.sin(2 * Math.PI * x / 23)
                - Math.cos(2 * Math.PI * x / 42)
                + Math.sin(2 * Math.PI * x / 7);
    }

    @Test
    public void testPage() {
        double[] doubles = new double[2048];
        
        for (int i = 0; i < doubles.length; i++) {
            doubles[i] = f(i);
        }
        
        TreeMap<Double, Integer> map = new PageDistribution().page(doubles);
        assertEquals(23, map.pollLastEntry().getValue().intValue());
        assertEquals(42, map.pollLastEntry().getValue().intValue());
        assertEquals(7, map.pollLastEntry().getValue().intValue());
    }

}
